<?php
/**
 *
 *
 */
namespace Yz\modules\News;

use Error,
    NotFoundError;
class Controller_ByName
    extends \Yz\modules\Generic\Controller_AbstractFetch
{

    protected $templateName = 'Entry';

    protected $item;
    protected $title;


    /** The list of required arguments for controller
     *  @var array
     */
    protected $arguments = array(
        'title',
    );

    /****************************
     *      Public methods      *
     ****************************/

    /** Custom error handler for entry
     *      Handles item-not-found
     *
     *  @return this|false
     */
    public function doError( Error $ex )
    {
        if ($ex instanceof NotFoundError) {
            return $this->_outputError(self::ERROR_ITEM_NOT_FOUND);
        }
        return false;
    }


    /*****************************
     *    Protected methods      *
     *****************************/



    protected function setTitle($title)
    {
        $this->title = rawurldecode($title);

        return $this;
    }


    /**
     *
     */
    protected function fetchData()
    {
        $model = $this->selectModel();
        $this->item = $model->fetchItemByTitle($this->title);
        return $this;
    }

    /**
     *
     */
    protected function assignTemplateParams(\Yz_Template_Interface $t)
    {
        $t->item = $this->item;
        return $this;
    }


}
